import { request } from '../../../services/request';
import { AsnUninstallQueryParams, AsnUninstallResponse } from './types';

export const queryAsnUninstall = async (params: AsnUninstallQueryParams): Promise<AsnUninstallResponse> => {
    console.log('请求参数:', params);

    try {
        const response = await request('/app/wms/asn/searchUploadTask', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('接口返回:', response);
        return response;
    } catch (error) {
        console.error('查询 ASN 失败:', error);
        throw error;
    }
};

export const confirmAsn = async (params: { uninstall_quantity: string; bus_num: string; product_id: string; sku_id: string }): Promise<any> => {
    console.log('确认到货请求参数:', params);

    try {
        const response = await request('/app/wms/asn/uninstall', {
            method: 'POST',
            body: JSON.stringify(params),
        });

        console.log('确认到货接口返回:', response);
        return response;
    } catch (error) {
        console.error('确认到货失败:', error);
        throw error;
    }
};

export const getBodyListByBusNum = async (bus_num: string): Promise<any> => {
    try {
        const response = await request('/app/wms/asn/getBodyListByBusNum', {
            method: 'POST',
            body: JSON.stringify({ bus_num }),
        });
        return response;
    } catch (error) {
        console.error('获取产品列表失败:', error);
        throw error;
    }
};

export const getProductSkuList = async (product_id: string): Promise<any> => {
    try {
        const response = await request('/app/appProduct/getProductSkuList', {
            method: 'POST',
            body: JSON.stringify({ product_id }),
        });
        return response;
    } catch (error) {
        console.error('获取SKU列表失败:', error);
        throw error;
    }
};
